/*
 * @Author: ZAL 2177624751@qq.com
 * @Date: 2025-03-29 13:29:41
 * @LastEditors: ZAL 2177624751@qq.com
 * @LastEditTime: 2025-03-31 16:58:04
 * @FilePath: \shop_app_vue3\api\login.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import request from '../utils/request.js';

// 登录
export const login = (data) => {
    if (data.type === 'mock') {
        return request.post('/user/mock-login');
    }
    return request.post('/user/login', data);
};

// 微信小程序登录
export const wxLogin = (code) => {
    return request.post('/user/wx-login', { code });
};

// 获取用户信息
export function getUserInfo() {
    return request.get('/user/info');
}

// 验证token
export const verifyToken = () => {
    return request.get('/user/info');
};

// 更新用户手机号
// params:
// - phone: 手机号
export const updatePhone = (phone) => {
    return request.put(`/user/phone?phone=${phone}`);
};

// 更新用户生日
// params:
// - birthday: 生日（格式：yyyy-MM-dd）
export const updateBirthday = (birthday) => {
    return request.put(`/user/birthday?birthday=${birthday}`);
};

// 更新用户昵称
// params:
// - nickname: 用户昵称
export const updateNickname = (nickname) => {
    return request.put(`/user/nickname?nickname=${nickname}`);
};

// 更新用户头像
// params:
// - avatarUrl: 头像URL
export const updateAvatar = (avatarUrl) => {
    return request.put(`/user/avatar?avatarUrl=${encodeURIComponent(avatarUrl)}`);
};

// 更新用户性别
// params:
// - gender: 性别（0-未知，1-男，2-女）
export const updateGender = (gender) => {
    return request.put(`/user/gender?gender=${gender}`);
};

// 更新用户邮箱
// params:
// - email: 邮箱
export const updateEmail = (email) => {
    return request.put(`/user/email?email=${encodeURIComponent(email)}`);
};

// 更新用户IP属地
// params:
// - ipLocation: IP属地
export const updateIpLocation = (ipLocation) => {
    return request.put(`/user/ip-location?ipLocation=${encodeURIComponent(ipLocation)}`);
};